//
//  UIImage+WBImage.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/19.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "UIImage+WBImage.h"
#import "WBEmoticonModel.h"
#import "WBEmoticonTool.h"

@implementation UIImage (WBImage)


+ (UIImage *)getImageWithModel:(WBEmoticonModel *)model
{
  return [UIImage imageNamed:[NSString stringWithFormat:@"%@/%@",model.path,model.png] inBundle:[WBEmoticonTool sharedEmoticonTool].emoticonBundle compatibleWithTraitCollection:nil];

}



+ (UIImage *)handleImage:(UIImage *)image andWidth:(CGFloat)width
{
    if(image.size.width < width)
    {
        return image;
        
    }
    
    //计算压缩的高度
    CGFloat imageH = image.size.height * width / image.size.width;
    
    CGRect rect = CGRectMake(0, 0, width, imageH);
    
    //开启上下文
    UIGraphicsBeginImageContext(rect.size);
    
    //渲染图片
    [image drawInRect:rect];
    
    //获取图片
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    
    //关闭上下文
    UIGraphicsEndImageContext();
    
    return result;
    
}

@end
